<?php /* @var $view Model3_View */?>
<div class="container">
    <div class="row" >
        <div class="span12 blockGray">
            <div class="blockInner">
                <h1>Mis Clientes</h1>
                <a class="btn" href="<?php echo $view->url(array('controller'=>'BackStore','action'=>'createOrder','module'=>'User'));?>" title="Agrega una orden manualmente">Agregar nueva orden</a>
                <div class="clear">&nbsp;</div>
                                <?php
                if(count($view->orders)>0)
                {
                ?>
                <div class="">
                    <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>Folio</th>
                                <th>Recurrente</th>
                                <th>Comprador</th>
                                <th>Pagado</th>
                                <th>Entregado</th>
                                <th>Fecha de pedido</th>
                                <th>Detalles</th>
                            </tr>
                        </thead>
                        <tbody>
                            
                            <?php
                                foreach ($view->orders as $order)
                                { //si son ordenes no recurrentes
                                   $img = '<img src="'.$view->getBaseUrl().'/images/ok-icon.png"/>';
                                    if($order->getRecurrent() == DefaultDb_Entities_M3CommerceOrder::RECURRENT_NOTACTIVE)
                                    { 
                                ?>
                                    <tr>
                                        <td><?php echo $order->getId(); ?></td>
                                        <td><?php echo $img = ($order->getOrderParent() != null)? $img : "";?></td>
                                        <?php if($order->getPointBuyer()&& $order->getBuyer()->getType() == DefaultDb_Entities_User::USER_CLIENT_MAS_DISTRIBUCION):?>
                                            <td><?php echo $order->getPointBuyer()->getAddress() . ' ('. $order->getPointBuyer()->getState()->getName(). ')' ;?></td>
                                        <?php else:?>
                                            <td><?php echo $order->getBuyer()->getCommercialName();?></td>
                                        <?php endif;?>
                                        <td><?php echo $order->getPaymentStatusString(); ?></td>
                                        <td><?php echo $order->getShippingStatusString(); ?></td>
                                        <td><?php ?></td>
                                        <td><?php echo '<a href="'.$view->url(array('controller' => 'BackStore', 'action' => 'viewOrder', 'id' => $order->getId())).'">Orden '.$order->getId().'</a>';?></td>
                                    </tr>
                                <?php
                                    }
                                }
                            ?>

                        </tbody>
                    </table>
                    <?php if($view->recurrentsFlag):?>
                      <table class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>Folio</th>
                                <th>Comprador</th>
                                <th>Pagado</th>
                                <th>Entregado</th>
                                <th>Fecha de pedido</th>
                                <th>Estado</th>
                                <th>Detalles</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                foreach ($view->orders as $order)
                                {// si son ordenes recurrentes
                                    if($order->getRecurrent() == DefaultDb_Entities_M3CommerceOrder::RECURRENT_ACTIVE) 
                                    {
                                ?>
                                    <tr>
                                        <td><?php echo $order->getId(); ?></td>
                                        <td><?php echo $order->getBuyer()->getFullName(); ?></td>
                                        <td><?php echo $order->getPaymentStatusString(); ?></td>
                                        <td><?php echo $order->getShippingStatusString(); ?></td>
                                        <td><?php ?></td>
                                        <td><?php echo $active = ($order->getOrderStatus() == DefaultDb_Entities_M3CommerceOrder::ORDER_STATUS_ACTIVE) ? 'Activa' : 'Inactiva' ;?></td>
                                        <td><?php echo '<a href="'.$view->url(array('controller' => 'BackStore', 'action' => 'viewOrder', 'id' => $order->getId())).'">Orden '.$order->getId().'</a>';?></td>
                                    </tr>
                                <?php
                                    }
                                }
                            ?>

                        </tbody>
                    </table>
                    <?php endif; ?>
                </div>
                <?php
                }
                else
                {
                    echo '<div class="alert alert-error">Actualmente no tiene ventas.</div>';
                }
                ?>
            </div>
        </div>
    </div>
</div>
